<?php
require_once $_SERVER['srcPath'].'/MessageFromApp.php';

use GrouppaGroup\MessageFromApp;

class MessageFromAppTest extends PHPUnit_Framework_TestCase
{
	/**
	 * @var MessageFromApp
	 */
	public $instance;
	protected function setUp()
	{
		$this->instance = new MessageFromApp();
	}
	
	public function dataForTest()
	{
		return array(	
				array((object)array(			
						'from' => 'MI6', 
						'id' => 007, 
						'serializedArguments' => 'I have no clue what that is',
						'task' => 'Operation Bravo', 
						'toController' => 'M, yeah that lady',
						'toGroup' => 'sexy ladies'
				))
				,
				array((object)array(
						'id' => 007,
						'toController' => 'M, yeah that lady',
						'toGroup' => 'sexy ladies'
				)),
				array((object)array(
						'id' => 007,
						'serializedArguments' => 'I have no clue what that is',
						'serializedArguments' => 'oh so that what that is',
						'task' => 'Operation Bravo',
						'toController' => 'M, yeah that lady',
						'toGroup' => 'sexy ladies'
				)),
				array((object)array(
						'id' => 007,
						'serializedArguments' => 'I have no clue what that is',
						'toController' => 'M, yeah that lady',
						'toGroup' => 'sexy ladies'
				))
		);

		//will provide arguements, they all have to be arrays inside arrays.
	}
	
	//test case for createFromJson class.
	/**
	 * 
	 * @dataProvider dataForTest
	 */
	public function testCreateFromJson($jsonMessage){
		$createdMessage = $this->instance->createFromJSON($jsonMessage);
		$this -> assertEquals( isset($jsonMessage -> from) ? $jsonMessage -> from:"" ,  $createdMessage-> from);
		$this -> assertEquals(isset($jsonMessage->id) ?$jsonMessage->id :"",$createdMessage->id );
		$this -> assertEquals(isset($jsonMessage->serializedArguments) ? $jsonMessage->serializedArguments:"",$createdMessage->serializedArguments );
		$this -> assertEquals(isset($jsonMessage->task) ? $jsonMessage->task:"",$createdMessage->task );
		$this -> assertEquals(isset($jsonMessage->toController) ? $jsonMessage->toController:"",$createdMessage->toController );
		$this -> assertEquals(isset($jsonMessage->toGroup) ?$jsonMessage->toGroup :"",$createdMessage->toGroup );
		$this -> assertEquals(isset($jsonMessage->messageType) ?$jsonMessage->messageType :"",$createdMessage->messageType );
		$this -> assertEquals(isset($jsonMessage->accessToken) ?$jsonMessage->accessToken :"",$createdMessage->accessToken );
	}
}